package com.biz.primus.ms.commodity.api;

import com.biz.primus.commodity.vo.keyword.KeywordQueryVo;
import com.biz.primus.commodity.vo.keyword.KeywordVo;
import com.biz.primus.common.vo.SpringPageVO;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.commodity.dao.redis.keyword.KeywordRedisDao;
import com.biz.primus.ms.commodity.dao.repository.product.keyword.KeywordRepository;
import com.biz.primus.ms.commodity.service.backend.keyword.KeywordBackendService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author nan.jiang
 * @date 2017/9/12
 */
@RestController
@RequestMapping("soa/keywordService")
public class KeywordApiController extends BaseApiController {

    private final KeywordRepository keywordRepository;

    private final KeywordRedisDao keywordRedisDao;

    private final KeywordBackendService keywordBackendService;

    @Autowired
    public KeywordApiController(KeywordRepository keywordRepository, KeywordRedisDao keywordRedisDao, KeywordBackendService keywordBackendService) {
        this.keywordRepository = keywordRepository;
        this.keywordRedisDao = keywordRedisDao;
        this.keywordBackendService = keywordBackendService;
    }

    @ApiOperation("查找所有关键字")
    @PostMapping("findAll")
    public SpringPageVO<KeywordVo> findAll(@RequestBody KeywordQueryVo keywordQueryVo) {
        return keywordBackendService.findAll(keywordQueryVo);
    }

    @ApiOperation("创建扩展属性")
    @PostMapping("saveOrUpdate")
    void saveOrUpdate(@RequestBody KeywordVo keywordVo){
        keywordBackendService.saveOrUpdate(keywordVo);
    }

    @ApiOperation("查找某个关键字")
    @GetMapping("findOne")
    public KeywordVo findOne(@RequestParam("id") Long id){
        return keywordBackendService.findOne(id);
    }

    @ApiOperation("删除关键字")
    @PostMapping("delete")
    public void delete(@RequestParam("id") Long id){
        keywordBackendService.delete(id);
    }
}
